package com.mars.miaosha.service;

import com.mars.miaosha.dao.GoodsDao;
import com.mars.miaosha.domain.MiaoshaUser;
import com.mars.miaosha.domain.OrderInfo;
import com.mars.miaosha.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *  秒杀，事务操作
 * @author MARS
 * @date 2018/5/11
 */
@Service
public class MiaoshaService {

    @Autowired
    private GoodsService goodsService;
    @Autowired
    private OrderServive orderServive;

    @Transactional
    public OrderInfo miaosha(MiaoshaUser user, GoodsVo goodsVo) {
        //  减少库存，下订单，写入秒杀订单(需要在一个事务里去完成的操作)
        goodsService.reduceStock(goodsVo);
        // 写订单(写入两个表，一个订单表，一个秒杀订单表表)
        return orderServive.createOrder(user,goodsVo);

    }


}
